package com.ruoyi.ncpsy.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ncpsy.domain.NcpsyCropFertilizer;
import com.ruoyi.ncpsy.service.INcpsyCropFertilizerService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 作物与肥料记录Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/ncpsy/fertcrop")
public class NcpsyCropFertilizerController extends BaseController
{
    @Autowired
    private INcpsyCropFertilizerService ncpsyCropFertilizerService;

    /**
     * 查询作物与肥料记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcpsyCropFertilizer ncpsyCropFertilizer)
    {
        startPage();
        List<NcpsyCropFertilizer> list = ncpsyCropFertilizerService.selectNcpsyCropFertilizerList(ncpsyCropFertilizer);
        return getDataTable(list);
    }

    /**
     * 导出作物与肥料记录列表
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:export')")
    @Log(title = "作物与肥料记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcpsyCropFertilizer ncpsyCropFertilizer)
    {
        List<NcpsyCropFertilizer> list = ncpsyCropFertilizerService.selectNcpsyCropFertilizerList(ncpsyCropFertilizer);
        ExcelUtil<NcpsyCropFertilizer> util = new ExcelUtil<NcpsyCropFertilizer>(NcpsyCropFertilizer.class);
        util.exportExcel(response, list, "作物与肥料记录数据");
    }

    /**
     * 获取作物与肥料记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:query')")
    @GetMapping(value = "/{fertRecordId}")
    public AjaxResult getInfo(@PathVariable("fertRecordId") Long fertRecordId)
    {
        return success(ncpsyCropFertilizerService.selectNcpsyCropFertilizerByFertRecordId(fertRecordId));
    }

    /**
     * 新增作物与肥料记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:add')")
    @Log(title = "作物与肥料记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcpsyCropFertilizer ncpsyCropFertilizer) throws Exception {
        System.out.println("ncpsyCropFertilizer" + ncpsyCropFertilizer);
        return toAjax(ncpsyCropFertilizerService.insertNcpsyCropFertilizer(ncpsyCropFertilizer));
    }

    /**
     * 修改作物与肥料记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:edit')")
    @Log(title = "作物与肥料记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcpsyCropFertilizer ncpsyCropFertilizer)
    {
        return toAjax(ncpsyCropFertilizerService.updateNcpsyCropFertilizer(ncpsyCropFertilizer));
    }

    /**
     * 删除作物与肥料记录
     */
    @PreAuthorize("@ss.hasPermi('ncpsy:fertcrop:remove')")
    @Log(title = "作物与肥料记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertRecordIds}")
    public AjaxResult remove(@PathVariable Long[] fertRecordIds)
    {
        return toAjax(ncpsyCropFertilizerService.deleteNcpsyCropFertilizerByFertRecordIds(fertRecordIds));
    }
}
